﻿using AutoMapper;
using B.S.DataBase.MyProject.Domain;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using B.S.DataBase.MyRead.API.Appicant.Command.Menus;
using B.S.DataBase.MyRead.API.DTOs;
using MediatR;
using Microsoft.EntityFrameworkCore;

namespace B.S.DataBase.MyRead.API.Appicant.CommandHandler.Menus
{
    public class GetRoleMenuTreeCommandHandler : IRequestHandler<GetRoleMenuTreeCommand, APIResult<List<RoleMenu>>>
    {
        private readonly IBaseRepository<RoleMenu> roleMenuRep;

      
        public GetRoleMenuTreeCommandHandler(IBaseRepository<RoleMenu> roleMenuRep)
        {
            this.roleMenuRep = roleMenuRep;

          
        }

        public async Task<APIResult<List<RoleMenu>>> Handle(GetRoleMenuTreeCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<RoleMenu>> result = new APIResult<List<RoleMenu>>();

            var list = roleMenuRep.GetAll().Result.Where(x => x.RoleId == request.RoleId);
            result.Code = APIEnum.查询成功;
            result.Msg = "查询成功";
            result.data = list.ToList();
            return await Task.FromResult(result);
        }


    }
}

